﻿using System;
using System.Windows.Forms;

namespace SksApp
{
    public partial class EvrakTasarimView : BaseView
    {
        public EvrakTasarimView()
        {
            InitializeComponent();
        }

        private void btnKapat_Click(object sender, EventArgs e)
        {
            this.Dispose();
            Event.Invoke(null, null);
        }

        private void EvrakTasarimView_Load(object sender, EventArgs e)
        {
            foreach (ReportTypeOption reportType in Enum.GetValues(typeof(ReportTypeOption)))
            {
                cmbNo.Items.Add(reportType.GetDescription());
            }
        }

        private void btnTasarim_Click(object sender, EventArgs e)
        {
            FastReport.Report sablon = ReportTemplate.DizaynAc((ReportTypeOption)Enum.Parse(typeof(ReportTypeOption), Enum.GetName(typeof(ReportTypeOption), cmbNo.SelectedIndex)));
            if (sablon != null)
            {
                ReportTypeOption op = (ReportTypeOption)Enum.Parse(typeof(ReportTypeOption), Enum.GetName(typeof(ReportTypeOption), cmbNo.SelectedIndex));
                System.Windows.Forms.BindingSource binding = null;
                switch (op)
                {
                    case ReportTypeOption.Fatura:
                    case ReportTypeOption.Iade:
                    case ReportTypeOption.Fis:
                        binding = new System.Windows.Forms.BindingSource { DataSource = new PrnInvoice() };
                        break;
                    case ReportTypeOption.Bekleme:
                        break;
                    case ReportTypeOption.ZRapor:
                        binding = new System.Windows.Forms.BindingSource { DataSource = new Rapor() };
                        break;
                    case ReportTypeOption.Raf13Etiket:
                    case ReportTypeOption.Raf8Etiket:
                    case ReportTypeOption.Urun13Etiket:
                    case ReportTypeOption.Urun8Etiket:
                        binding = new System.Windows.Forms.BindingSource { DataSource = new Etiket() };
                        break;
                    case ReportTypeOption.Tahsilat:
                        break;
                    case ReportTypeOption.Odeme:
                        break;
                    default:
                        break;
                }
                sablon.RegisterData(binding, "Tasarim", 10);
                sablon.GetDataSource("Tasarim").Enabled = true;
                if (sablon.Design(true))
                {
                    ReportTemplate.DizaynKaydet(op, ReportTemplate.GetPath(op));
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.FileName = "";
                dlg.InitialDirectory = ReportTemplate.GetPath();
                dlg.Filter = "Dizayn Dosyaları|*.dzn";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    ReportTemplate.DizaynKaydet((ReportTypeOption)Enum.Parse(typeof(ReportTypeOption), Enum.GetName(typeof(ReportTypeOption), cmbNo.SelectedIndex)), dlg.FileName);
                }
            }
        }
    }
}
